/** 
 * @Description: 模型加载
 * @Author: 程前
 * @Date: 2024-12-09 15:38:51
 * @LastEditors: 程前
 * @LastEditTime: 2024-12-26 15:38:28
 */
import { Viewer, Entity, ScreenSpaceEventHandler } from "cesium";
import BaseLoader from "../base"
import { ICesiumLoader } from "@/types/loader";
import CesiumModel from "@/cesium/model";
import { useCesiumGlobalStore } from "@/store/modules/cesiun-global"
import { useCesiumEditStore } from "@/store/modules/cesium-edit";


type ModelOptions = {
    modelUrl: string
    handler: ScreenSpaceEventHandler;
}
export default class Model extends BaseLoader implements ICesiumLoader {
    viewer: Viewer;
    entity: Entity;
    loader: CesiumModel;
    src: string = '';
    coverSrc: string = '';
    handler: ScreenSpaceEventHandler | null = null
    constructor(viewer: Viewer, options?: Omit<ModelOptions, 'handler'>) {
        super(viewer);
        this.viewer = viewer;
        this.handler = new ScreenSpaceEventHandler(this.viewer.scene.canvas);
        this.init(viewer, this.handler);
    }

    init(viewer: Viewer, handler: ScreenSpaceEventHandler): void {
        this.loader = new CesiumModel(viewer, handler);
        this.loader.initEvents()
    }


    getData(): Record<string, any> {
        throw new Error('Method not implemented.');
    }

    getEntity(): Entity | void {
        throw new Error('Method not implemented.');
    }

    remove(): boolean {
        throw new Error('Method not implemented.');
    }

    destroy(): void {
        this.loader.destroy()
        super.removeEscEvent()
        useCesiumGlobalStore().loader = null
        //重置默认配置
        const cesiumEditStore = useCesiumEditStore()
        cesiumEditStore.model.config = {
            label: "",
            labelColor: "#fff",
            pixel: 24,
            scale: 50,
            rotation: 0
        }
    }
}